using System.IO;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Messaging;
using Universe.Remoting.Sinks;

namespace Universe.Remoting.Extensions
{
    class TransparentDeliveryServerSink : BaseCustomSink
    {
        protected override void ProcessRequest(IMessage message, ITransportHeaders headers, ref Stream stream, ref object state)
        {
            IMethodMessage mm = message as IMethodMessage;
            if (mm != null)
            {
                object raw = mm.LogicalCallContext.GetData(ContextData.SlotName);

                ContextData data = raw as ContextData;
                DeliveryDictionary dict =
                    data != null
                    ? data.Deserialize()
                    : new DeliveryDictionary();

                TransparentDeliveryConfiguration.OnServer(dict);
            }
        }
    }
}
